package at.codebase.db.entities;

/**
 * @author Daniel Marth <danielmarth@gmx.at>
 * @author Lukas Pfeifhofer <lukas.pfeifhofer@devlabs.pro>
 */
public class EItem {

	private Long itemId;

	private String title;
	private String description;
	private boolean active;
	private boolean deleted;
	private double price;

	private long timeCreate;
	private long timeExpiration;

	private boolean useLocation;
	private double latitude;
	private double longitude;

	public EItem() {

	}

	public EItem(String title, String description,
			boolean active, boolean deleted, double price, long timeCreate,
			long timeExpiration) {
		this(title, description, active, deleted, price, timeCreate,
				timeExpiration, 0.0, 0.0);
		this.useLocation = false;
	}

	public EItem(String title, String description,
			boolean active, boolean deleted, double price, long timeCreate,
			long timeExpiration, double latitude, double longitude) {
		this.title = title;
		this.description = description;
		this.active = active;
		this.deleted = deleted;
		this.price = price;
		this.timeCreate = timeCreate;
		this.timeExpiration = timeExpiration;
		this.latitude = latitude;
		this.longitude = longitude;
		this.useLocation = true;
	}

	public static EItem createItem(String itemTitle,
			String itemDescription, double itemPrice, long timeCreate,
			long timeExpiration) {
		return new EItem(itemTitle, itemDescription, true, false,
				itemPrice, timeCreate, timeExpiration);
	}

	public static EItem createItem(String itemTitle,
			String itemDescription, double itemPrice, long timeCreate,
			long timeExpiration, double latitude, double longitude) {
		return new EItem(itemTitle, itemDescription, true, false,
				itemPrice, timeCreate, timeExpiration, latitude, longitude);
	}

	public Long getId() {
		return itemId;
	}

	public void setId(Long itemId) {
		this.itemId = itemId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public boolean isDeleted() {
		return deleted;
	}

	public void setDeleted(boolean deleted) {
		this.deleted = deleted;
	}

	public double getPrice() {
		return price;
	}

	public void setPrice(double price) {
		this.price = price;
	}

	public long getTimeCreate() {
		return timeCreate;
	}

	public void setTimeCreate(long timeCreate) {
		this.timeCreate = timeCreate;
	}

	public long getTimeExpiration() {
		return timeExpiration;
	}

	public void setTimeExpiration(long timeExpiration) {
		this.timeExpiration = timeExpiration;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public double getLatitude() {
		return latitude;
	}

	public void setLocation(double latitude, double longitude) {
		this.latitude = latitude;
		this.longitude = longitude;
		this.useLocation = true;
	}

	public double getLongitude() {
		return longitude;
	}

	@Override
	public String toString() {
		return "EItem [itemId=" + itemId + ", seller="+ ", title="
				+ title + ", description=" + description + ", active=" + active
				+ ", deleted=" + deleted + ", price=" + price + ", timeCreate="
				+ timeCreate + ", timeExpiration=" + timeExpiration
				+ ", latitude=" + latitude + ", longitude=" + longitude
				+ ", imageKeys=" + "]";
	}

	public GeoPoint getLocation() {
		if(!useLocation) {
			return null;
		}
		return new GeoPoint(latitude, longitude);
	}
	
	public void setLocation(GeoPoint location) {
		if(location == null) {
			latitude = longitude = 0.0;
			useLocation = false;
		} else {
			latitude = location.getLatitude();
			longitude = location.getLongitude();
			useLocation = true;
		}
	}

}
